package hnxmh5

import (
	"github.com/gin-gonic/gin"
	"github.com/shopspring/decimal"
	"log"
	"strconv"
	"time"
	"yundian/internel/app/dao"
	"yundian/internel/app/helper"
	"yundian/internel/app/helper/resphelper"
	"yundian/internel/app/models/devices"
	"yundian/internel/pkg/dingo"
	. "yundian/internel/pkg/dingo/result"
	"yundian/internel/pkg/utils"
)

//统计收益
func StatisticalEarnings(c *gin.Context) {
	// 总销售  总订单 设备总数
	userId, err := helper.GetUserIdFromCtx(c)
	if err != nil {
		Response(c)(err.Error(), CodeNeedLogin, nil)(Unauthorized)
		return
	}
	isAdmin, err := helper.GetIsAdminFromCtx(c)
	if err != nil {
		Response(c)(err.Error(), CodeNeedLogin, nil)(Unauthorized)
		return
	}

	isPlace, err := helper.GetIsPlaceFromCtx(c)
	if err != nil {
		Response(c)(err.Error(), CodeNeedLogin, nil)(Unauthorized)
		return
	}

	var balance, tbalance, mbalance string
	var todayMoney, yesMoney, todayzz, week, yesWeek, lastWeek, weekzz, totalMoney, totalCount, deviceCount, todayOrderCount, usedDevice, deployDevice int64
	var deviceTypeCount []devices.DeviceTotal
	_, rowsAffected := dao.NewUserDao().GetAgentIsDraw(userId)
	//分公司
	if isPlace == 3 {
		//没有抽单权限
		// 余额 = (分红+抽单)-提现
		if rowsAffected > 0 {
			d := dao.NewOrderDao().GetDividendsMoneyByUserId(userId).Unwrap().(int64) // 分红
			t := dao.NewOrderDao().GetTakeTotalMoneyByUserId(userId).Unwrap().(int64) // 抽单
			c := dao.NewOrderDao().GetCashLogByUserId(userId).Unwrap().(int64)        // 提现
			balance = utils.Fen2Yuan((d + t) - c)                                     // 余额
			//balance = decimal.NewFromInt(d).Abs(decimal.NewFromInt(t)).Sub(decimal.NewFromInt(c)).
			//	Div(decimal.NewFromInt(100)).Truncate(2).String()

			// 今日入帐 = (分红+抽单)-提现
			td := dao.NewOrderDao().GetTodayDividendsMoneyByUserId(userId).Unwrap().(int64)          // 当天分红
			tt := dao.NewOrderDao().GetTodayTakeTotalMoneyByUserId(userId, isAdmin).Unwrap().(int64) // 当天抽单
			tc := dao.NewOrderDao().GetTodayCashLogByUserId(userId).Unwrap().(int64)                 // 当天提现
			tbalance = utils.Fen2Yuan((td + tt) - tc)                                                // 当天入帐
			//tbalance = decimal.NewFromInt(td).Sub(decimal.NewFromInt(tc)).
			//	Div(decimal.NewFromInt(100)).Truncate(2).String()
			//查询上个月收益
			md := dao.NewOrderDao().GetToMonthDividendsMoneyByUserId(userId).Unwrap().(int64)
			mt := dao.NewOrderDao().GetToMonthTakeTotalMoneyByUserId(userId, isAdmin).Unwrap().(int64) // 上个月抽单
			mc := dao.NewOrderDao().GetToMonthCashLogByUserId(userId).Unwrap().(int64)                 // 上个月提现
			mbalance = utils.Fen2Yuan((md + mt) - mc)

		} else {
			d := dao.NewOrderDao().GetDividendsMoneyByUserId(userId).Unwrap().(int64) // 分红
			//t := dao.NewOrderDao().GetTakeTotalMoneyByUserId(userId).Unwrap().(int64) // 抽单
			c := dao.NewOrderDao().GetCashLogByUserId(userId).Unwrap().(int64) // 提现
			//balance = utils.Fen2Yuan((d + t) - c)                                     // 余额
			balance = decimal.NewFromInt(d).Sub(decimal.NewFromInt(c)).
				Div(decimal.NewFromInt(100)).Truncate(2).String()

			// 今日入帐 = (分红+抽单)-提现
			td := dao.NewOrderDao().GetTodayDividendsMoneyByUserId(userId).Unwrap().(int64) // 当天分红
			//tt := dao.NewOrderDao().GetTodayTakeTotalMoneyByUserId(userId, isAdmin).Unwrap().(int64) // 当天抽单
			tc := dao.NewOrderDao().GetTodayCashLogByUserId(userId).Unwrap().(int64) // 当天提现
			//tbalance = utils.Fen2Yuan((td + tt) - tc)                                        // 当天入帐
			tbalance = decimal.NewFromInt(td).Sub(decimal.NewFromInt(tc)).
				Div(decimal.NewFromInt(100)).Truncate(2).String()

			md := dao.NewOrderDao().GetToMonthDividendsMoneyByUserId(userId).Unwrap().(int64)
			mc := dao.NewOrderDao().GetToMonthCashLogByUserId(userId).Unwrap().(int64) // 上个月提现

			mbalance = decimal.NewFromInt(md).Sub(decimal.NewFromInt(mc)).
				Div(decimal.NewFromInt(100)).Truncate(2).String()
		}

		childUserIds := dao.NewUserDao().QueryChildUserIds(userId).Unwrap().([]int)
		placesIdArr := dao.NewUserDao().GetPlacesIds(userId, childUserIds).Unwrap().([]int)

		//当天的销售额
		todayMoney = dao.NewOrderDao().QueryPlacesTodayTotalMoney(time.Now().Format("2006-01-02"), placesIdArr).Unwrap().(int64) // 当天的销售额

		// 前日销售额
		//lastMoney := dao.NewOrderDao().
		//	GetTodayTotalMoney(time.Now().AddDate(0, 0, -2).Format("2006-01-02")).
		//	Unwrap().(int64)
		// 昨日销售额
		yesMoney = dao.NewOrderDao().
			QueryPlacesTodayTotalMoney(time.Now().AddDate(0, 0, -1).Format("2006-01-02"), placesIdArr).
			Unwrap().(int64)
		todayzz = (todayMoney - yesMoney) / 100 // 日同比
		//todayzz := (yesMoney - lastMoney) / 100 // 日同比

		//week = dao.NewOrderDao().GetWeekTotalMoney(0).Unwrap().(int64)     // 本周
		yesWeek = dao.NewOrderDao().GetWeekTotalMoneyPlaces(1, placesIdArr).Unwrap().(int64) // 上周
		//lastWeek = dao.NewOrderDao().GetWeekTotalMoney(2).Unwrap().(int64) // 上上周

		//weekzz := (week - yesWeek) / 100                                   // 周同比
		//weekzz = (yesWeek - lastWeek) / 100 // 周同比

		dataTotalMoney := dao.NewOrderDao().GetTotalMoneyPlaces(placesIdArr)
		totalMoney = dataTotalMoney.Unwrap().(int64) // 已结算的订单总金额
		totalCount = dataTotalMoney.Val().(int64)    // 已结算的订单总笔数
		deviceCount = dao.NewDeviceDao().GetDeviceCountPlaces(placesIdArr).Unwrap().(int64)
		todayOrderCount = dao.NewOrderDao().GetTodayOrderCountPlaces(time.Now().Format("2006-01-02"), placesIdArr).Unwrap().(int64)

		usedDevice = dao.NewDeviceDao().GetUsedDeviceTotalPlaces(placesIdArr).Unwrap().(int64)     //获取代理设备总条数
		deployDevice = dao.NewDeviceDao().GetDeployDeviceTotalPlaces(placesIdArr).Unwrap().(int64) //已部署密码线统计
		deviceTypeCount = dao.NewDeviceDao().GetDeviceTotalByTypePlaces(placesIdArr).Unwrap().([]devices.DeviceTotal)

	}

	//代理商
	if isAdmin == 3 && isPlace != 3 { // 代理商 如果也享受抽单功能的话，需要判断一下
		log.Println(userId)
		//查询代理商是否能抽单

		//享受抽单功能
		if rowsAffected > 0 {
			d := dao.NewOrderDao().GetDividendsMoneyByUserId(userId).Unwrap().(int64) // 分红
			t := dao.NewOrderDao().GetTakeTotalMoneyByUserId(userId).Unwrap().(int64) // 抽单
			c := dao.NewOrderDao().GetCashLogByUserId(userId).Unwrap().(int64)        // 提现
			balance = utils.Fen2Yuan((d + t) - c)                                     // 余额
			//balance = decimal.NewFromInt(d).Abs(decimal.NewFromInt(t)).Sub(decimal.NewFromInt(c)).
			//	Div(decimal.NewFromInt(100)).Truncate(2).String()

			// 今日入帐 = (分红+抽单)-提现
			td := dao.NewOrderDao().GetTodayDividendsMoneyByUserId(userId).Unwrap().(int64)          // 当天分红
			tt := dao.NewOrderDao().GetTodayTakeTotalMoneyByUserId(userId, isAdmin).Unwrap().(int64) // 当天抽单
			tc := dao.NewOrderDao().GetTodayCashLogByUserId(userId).Unwrap().(int64)                 // 当天提现
			tbalance = utils.Fen2Yuan((td + tt) - tc)                                                // 当天入帐
			//tbalance = decimal.NewFromInt(td).Sub(decimal.NewFromInt(tc)).
			//	Div(decimal.NewFromInt(100)).Truncate(2).String()
			//查询上个月收益
			md := dao.NewOrderDao().GetToMonthDividendsMoneyByUserId(userId).Unwrap().(int64)
			mt := dao.NewOrderDao().GetToMonthTakeTotalMoneyByUserId(userId, isAdmin).Unwrap().(int64) // 上个月抽单
			mc := dao.NewOrderDao().GetToMonthCashLogByUserId(userId).Unwrap().(int64)                 // 上个月提现
			mbalance = utils.Fen2Yuan((md + mt) - mc)

		} else {
			d := dao.NewOrderDao().GetDividendsMoneyByUserId(userId).Unwrap().(int64) // 分红
			//t := dao.NewOrderDao().GetTakeTotalMoneyByUserId(userId).Unwrap().(int64) // 抽单
			c := dao.NewOrderDao().GetCashLogByUserId(userId).Unwrap().(int64) // 提现
			//balance = utils.Fen2Yuan((d + t) - c)                                     // 余额
			balance = decimal.NewFromInt(d).Sub(decimal.NewFromInt(c)).
				Div(decimal.NewFromInt(100)).Truncate(2).String()

			// 今日入帐 = (分红+抽单)-提现
			td := dao.NewOrderDao().GetTodayDividendsMoneyByUserId(userId).Unwrap().(int64) // 当天分红
			//tt := dao.NewOrderDao().GetTodayTakeTotalMoneyByUserId(userId, isAdmin).Unwrap().(int64) // 当天抽单
			tc := dao.NewOrderDao().GetTodayCashLogByUserId(userId).Unwrap().(int64) // 当天提现
			//tbalance = utils.Fen2Yuan((td + tt) - tc)                                        // 当天入帐
			tbalance = decimal.NewFromInt(td).Sub(decimal.NewFromInt(tc)).
				Div(decimal.NewFromInt(100)).Truncate(2).String()

			md := dao.NewOrderDao().GetToMonthDividendsMoneyByUserId(userId).Unwrap().(int64)
			mc := dao.NewOrderDao().GetToMonthCashLogByUserId(userId).Unwrap().(int64) // 上个月提现

			mbalance = decimal.NewFromInt(md).Sub(decimal.NewFromInt(mc)).
				Div(decimal.NewFromInt(100)).Truncate(2).String()
		}

		userIdArr := dao.NewUserDao().QueryChildUserIds(userId).Unwrap().([]int)
		log.Println(userIdArr)

		//当天的销售额
		todayMoney = dao.NewOrderDao().QueryChildTodayTotalMoney(time.Now().Format("2006-01-02"), userIdArr).Unwrap().(int64) // 当天的销售额

		// 前日销售额
		//lastMoney := dao.NewOrderDao().
		//	GetTodayTotalMoney(time.Now().AddDate(0, 0, -2).Format("2006-01-02")).
		//	Unwrap().(int64)
		// 昨日销售额
		yesMoney = dao.NewOrderDao().
			QueryChildTodayTotalMoney(time.Now().AddDate(0, 0, -1).Format("2006-01-02"), userIdArr).
			Unwrap().(int64)
		todayzz = (todayMoney - yesMoney) / 100 // 日同比
		//todayzz := (yesMoney - lastMoney) / 100 // 日同比

		//week = dao.NewOrderDao().GetWeekTotalMoney(0).Unwrap().(int64)     // 本周
		yesWeek = dao.NewOrderDao().GetWeekTotalMoneyChild(1, userIdArr).Unwrap().(int64) // 上周
		//lastWeek = dao.NewOrderDao().GetWeekTotalMoney(2).Unwrap().(int64) // 上上周

		//weekzz := (week - yesWeek) / 100                                   // 周同比
		//weekzz = (yesWeek - lastWeek) / 100 // 周同比

		dataTotalMoney := dao.NewOrderDao().GetTotalMoneyChild(userIdArr)
		totalMoney = dataTotalMoney.Unwrap().(int64) // 已结算的订单总金额
		totalCount = dataTotalMoney.Val().(int64)    // 已结算的订单总笔数
		deviceCount = dao.NewDeviceDao().GetDeviceCountChild(userIdArr).Unwrap().(int64)
		todayOrderCount = dao.NewOrderDao().GetTodayOrderCountChild(time.Now().Format("2006-01-02"), userIdArr).Unwrap().(int64)

		usedDevice = dao.NewDeviceDao().GetUsedDeviceTotalChild(userIdArr).Unwrap().(int64)
		deployDevice = dao.NewDeviceDao().GetDeployDeviceTotalChild(userIdArr).Unwrap().(int64)
		deviceTypeCount = dao.NewDeviceDao().GetDeviceTotalByTypeChild(userIdArr).Unwrap().([]devices.DeviceTotal)

	}
	// 运营商或管理员
	if isAdmin == 2 {

		// 余额 = (分红+抽单)-提现
		d := dao.NewOrderDao().GetDividendsMoneyByUserId(userId).Unwrap().(int64) // 分红
		//t := dao.NewOrderDao().GetTakeTotalMoneyByUserId(userId).Unwrap().(int64) // 抽单
		c := dao.NewOrderDao().GetCashLogByUserId(userId).Unwrap().(int64) // 提现
		//balance = utils.Fen2Yuan((d + t) - c)                                     // 余额
		balance = decimal.NewFromInt(d).Sub(decimal.NewFromInt(c)).
			Div(decimal.NewFromInt(100)).Truncate(2).String()

		// 今日入帐 = (分红+抽单)-提现
		td := dao.NewOrderDao().GetTodayDividendsMoneyByUserId(userId).Unwrap().(int64) // 当天分红
		//tt := dao.NewOrderDao().GetTodayTakeTotalMoneyByUserId(userId, isAdmin).Unwrap().(int64) // 当天抽单
		tc := dao.NewOrderDao().GetTodayCashLogByUserId(userId).Unwrap().(int64) // 当天提现
		//tbalance = utils.Fen2Yuan((td + tt) - tc)                                        // 当天入帐
		tbalance = decimal.NewFromInt(td).Sub(decimal.NewFromInt(tc)).
			Div(decimal.NewFromInt(100)).Truncate(2).String()

		todayMoney = dao.NewOrderDao().
			GetTodayTotalMoney(time.Now().Format("2006-01-02")).Unwrap().(int64) // 当天的销售额
		// 前日销售额
		//lastMoney := dao.NewOrderDao().
		//	GetTodayTotalMoney(time.Now().AddDate(0, 0, -2).Format("2006-01-02")).
		//	Unwrap().(int64)
		// 昨日销售额
		yesMoney = dao.NewOrderDao().
			GetTodayTotalMoney(time.Now().AddDate(0, 0, -1).Format("2006-01-02")).
			Unwrap().(int64)
		todayzz = (todayMoney - yesMoney) / 100 // 日同比
		//todayzz := (yesMoney - lastMoney) / 100 // 日同比

		week = dao.NewOrderDao().GetWeekTotalMoney(0).Unwrap().(int64)     // 本周
		yesWeek = dao.NewOrderDao().GetWeekTotalMoney(1).Unwrap().(int64)  // 上周
		lastWeek = dao.NewOrderDao().GetWeekTotalMoney(2).Unwrap().(int64) // 上上周

		//weekzz := (week - yesWeek) / 100                                   // 周同比
		weekzz = (yesWeek - lastWeek) / 100 // 周同比

		dataTotalMoney := dao.NewOrderDao().GetTotalMoney()
		totalMoney = dataTotalMoney.Unwrap().(int64) // 已结算的订单总金额
		totalCount = dataTotalMoney.Val().(int64)    // 已结算的订单总笔数

		deviceCount = dao.NewDeviceDao().GetDeviceCount().Unwrap().(int64)
		todayOrderCount = dao.NewOrderDao().GetTodayOrderCount(time.Now().Format("2006-01-02")).Unwrap().(int64)

		usedDevice = dao.NewDeviceDao().GetUsedDeviceTotal().Unwrap().(int64)
		deployDevice = dao.NewDeviceDao().GetDeployDeviceTotal().Unwrap().(int64)
		deviceTypeCount = dao.NewDeviceDao().GetDeviceTotalByType().Unwrap().([]devices.DeviceTotal)

	}

	// 先一个一个的计算出来，没问题后，归类 到一张表里，然后定时更新
	total := &struct {
		OrderMoneyTotal        string                `json:"order_money_total"`    // 已完成的订单总金额
		OrderCount             int64                 `json:"order_count"`          // 订单总笔数
		TodayOrderTotalMoney   string                `json:"today_total_money"`    // 今日销售金额
		YesOrderTotalMoney     string                `json:"yes_total_money"`      // 昨日销售金额
		WeekOrderTotalMoney    string                `json:"week_total_money"`     // 本周销售金额
		YesWeekOrderTotalMoney string                `json:"yes_week_total_money"` // 上周销售金额
		TodayOrderCount        int64                 `json:"today_order_count"`    // 今日销售订单数
		Balance                string                `json:"balance"`              // 余额
		DeviceCount            int64                 `json:"device_count"`         // 设备条数
		DayCompared            int64                 `json:"day_compared"`         // 日同比
		WeekCompared           int64                 `json:"week_compared"`        // 周同比
		TodayBalance           string                `json:"today_balance"`        // 当天入帐
		UsedDevice             int64                 `json:"used_device"`          // 使用中的设备 (所有类型的设备)
		DeployDevice           int64                 `json:"deploy_device"`        // 已部署的设备 (所有类型的设备)
		MonthBalance           string                `json:"month_balance"`
		DeviceTypeCount        []devices.DeviceTotal `json:"device_type_count"` // 设备类型统计
	}{
		OrderMoneyTotal:        utils.Fen2Yuan(totalMoney),
		OrderCount:             totalCount,
		Balance:                balance,
		DeviceCount:            deviceCount,
		DayCompared:            todayzz,
		WeekCompared:           weekzz,
		TodayOrderTotalMoney:   utils.Fen2Yuan(todayMoney),
		TodayOrderCount:        todayOrderCount,
		TodayBalance:           tbalance,
		UsedDevice:             usedDevice,
		DeployDevice:           deployDevice,
		DeviceTypeCount:        deviceTypeCount,
		YesOrderTotalMoney:     utils.Fen2Yuan(yesMoney),
		WeekOrderTotalMoney:    utils.Fen2Yuan(week),
		YesWeekOrderTotalMoney: utils.Fen2Yuan(yesWeek),
		MonthBalance:           mbalance,
	}

	Response(c)("", CodeSuccess, total)(OK)

}

//统计收益
func GetEarningsList(c *gin.Context) {
	param := &struct {
		SharedMode string `form:"sharedMode"` // 共享模型
		TimeRange  string `form:"timeRange"`  // 查询条件时间
	}{}

	dingo.ErrorIf(c.ShouldBindQuery(param)).Unwrap()

	userId, err := helper.GetUserIdFromCtx(c) // 获取当前代理商ID
	if err != nil {
		Response(c)(err.Error(), CodeNeedLogin, nil)(Unauthorized)
		return
	}
	isAdmin, err := helper.GetIsAdminFromCtx(c) // 从上下文中获取用户是否为管理员
	if err != nil {
		Response(c)(err.Error(), CodeNeedLogin, nil)(Unauthorized)
		return
	}

	isPlace, err := helper.GetIsPlaceFromCtx(c)
	if err != nil {
		Response(c)(err.Error(), CodeNeedLogin, nil)(Unauthorized)
		return
	}

	//userId := 2
	//isAdmin := uint8(2)
	//isPlace := uint8(0)

	lineData := dao.NewOrderDao().GetEarningsStatisticalList(param.SharedMode, param.TimeRange, isAdmin, userId, isPlace).Unwrap()
	toDayIncome := dao.NewOrderDao().GetEarningsIncome(userId, param.SharedMode).Unwrap().(int64)
	Response(c)("", CodeSuccess, &struct {
		LineData    []*resphelper.ChartListResp `json:"lineData"`
		ToDayIncome int64                       `json:"toDayIncome"`
	}{
		LineData:    lineData.([]*resphelper.ChartListResp),
		ToDayIncome: toDayIncome,
	})(OK)
}

//事项展示
func GetMattersList(c *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(c) // 获取当前代理商ID
	if err != nil {
		Response(c)(err.Error(), CodeNeedLogin, nil)(Unauthorized)
		return
	}
	//userId := 2
	var userIdArr, placeIdArr []int
	if userId != 2 {
		userIdArr = dao.NewUserDao().QueryChildUserIds(userId).Unwrap().([]int)
		placeIdArr = dao.NewPlaceDao().GetPlaceByIds(userIdArr).Unwrap().([]int)
	}

	if len(placeIdArr) <= 0 {
		Response(c)("", CodeSuccess, &struct {
			DeviceCount    int64  `json:"deviceCount"`
			UseDeviceCount int64  `json:"useDeviceCount"`
			DeviceUsage    string `json:"deviceUsage"`
			DeviceUnused   string `json:"deviceUnused"`
			OrderCount     int64  `json:"orderCount"`
			PlaceCount     int64  `json:"placeCount"`
			PlaceUsage     string `json:"placeUsage"`
			PlaceUnused    string `json:"placeUnused"`
		}{
			DeviceCount:    0,   //设备总数
			UseDeviceCount: 0,   //设备使用总数
			DeviceUsage:    "0", //设备使用率
			DeviceUnused:   "0", //设备未使用率
			OrderCount:     0,   //今日订单量
			PlaceCount:     0,   //网点总数
			PlaceUsage:     "0", //网点使用率
			PlaceUnused:    "0", //网点未使用率
		})(OK)
		return
	}

	//查询是否可以抽单
	isDraw := dao.NewUserDao().GetUserIsDraw(userId).Unwrap().(int)

	deviceCount := dao.NewOrderDao().GetMattersCountDevice(placeIdArr, userId).Unwrap().(int64)
	//useDeviceCount := dao.NewOrderDao().GetMattersDeviceUse(placeIdArr, isDraw).Unwrap().(int64)

	useDeviceCount := dao.NewDeviceDao().GetUsedDeviceTotalStatistical(placeIdArr, userId).Unwrap().(int64) //获取代理设备总条数

	orderCount := dao.NewOrderDao().GetMattersOrderCount(placeIdArr, isDraw, userId).Unwrap().(int64)

	//设备使用率
	deviceUsage := decimal.NewFromFloat32(float32(useDeviceCount)).Div(decimal.NewFromFloat32(float32(deviceCount))).Mul(decimal.NewFromInt(100)).StringFixed(2)

	//设备未使用率
	deviceUsageInt, _ := strconv.ParseFloat(deviceUsage, 64)
	deviceUnused := decimal.NewFromInt(100).Sub(decimal.NewFromFloat32(float32(deviceUsageInt))).StringFixed(2)
	var placeCount int64
	//网点总数
	if userId == 2 {
		placeCount = dao.NewOrderDao().GetUserPlaceCount().Unwrap().(int64)
	} else {
		placeCount = int64(len(placeIdArr))
	}

	//网点使用率
	usePlaceCount := dao.NewOrderDao().GetMattersPlaceUse(placeIdArr, userId).Unwrap().(int64)
	placeUsage := decimal.NewFromFloat32(float32(usePlaceCount)).Div(decimal.NewFromFloat32(float32(len(placeIdArr)))).Mul(decimal.NewFromInt(100)).StringFixed(2)

	//设备未使用率
	//placeUsageInt, _ := strconv.Atoi(placeUsage)
	//placeUnused := strconv.Itoa(100 - placeUsageInt)
	placeUsageInt, _ := strconv.ParseFloat(placeUsage, 64)
	placeUnused := decimal.NewFromInt(100).Sub(decimal.NewFromFloat32(float32(placeUsageInt))).StringFixed(2)

	Response(c)("", CodeSuccess, &struct {
		DeviceCount    int64  `json:"deviceCount"`
		UseDeviceCount int64  `json:"useDeviceCount"`
		DeviceUsage    string `json:"deviceUsage"`
		DeviceUnused   string `json:"deviceUnused"`
		OrderCount     int64  `json:"orderCount"`
		PlaceCount     int64  `json:"placeCount"`
		PlaceUsage     string `json:"placeUsage"`
		PlaceUnused    string `json:"placeUnused"`
	}{
		DeviceCount:    deviceCount,    //设备总数
		UseDeviceCount: useDeviceCount, //设备使用总数
		DeviceUsage:    deviceUsage,    //设备使用率
		DeviceUnused:   deviceUnused,   //设备未使用率
		OrderCount:     orderCount,     //今日订单量
		PlaceCount:     placeCount,     //网点总数
		PlaceUsage:     placeUsage,     //网点使用率
		PlaceUnused:    placeUnused,    //网点未使用率
	})(OK)
}
